package cn.honglian.system.controller;

import cn.honglian.basic.util.AjaxResult;
import cn.honglian.basic.util.PageList;
import cn.honglian.system.domain.Systemdictionarytype;
import cn.honglian.system.query.SystemdictionarytypeQuery;
import cn.honglian.system.service.SystemdictionarytypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/type")
public class SystemdictionarytypeController {

    @Autowired
    private SystemdictionarytypeService systemdictionarytypeService;

    @GetMapping()
    public List<Systemdictionarytype> findAll(){
        return systemdictionarytypeService.findAll();
    }

    @PostMapping()
    public PageList queryBypage(@RequestBody SystemdictionarytypeQuery systemdictionarytypeQuery){

        return systemdictionarytypeService.queryByPage(systemdictionarytypeQuery);
    }
    @DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable("id") Long id){
        try {
            systemdictionarytypeService.delete(id);
        } catch (Exception e){
            e.printStackTrace();
            return AjaxResult.me().fail();
        }
        return AjaxResult.me().success();
    }

    @PatchMapping()
    public AjaxResult batchDelete(@RequestBody List<Long> ids){

        try {
            systemdictionarytypeService.batchDelete(ids);
        } catch (Exception e){
            e.printStackTrace();
            return AjaxResult.me().fail();
        }
        return AjaxResult.me().success();
    }
    @PutMapping()
    public AjaxResult addAndUpdate(@RequestBody Systemdictionarytype systemdictionarytype){

        try {
            if (null!= systemdictionarytype.getId()){
                systemdictionarytypeService.update(systemdictionarytype);
            }else {
                systemdictionarytypeService.add(systemdictionarytype);
            }

        }catch (Exception e){
            e.printStackTrace();
            return AjaxResult.me().fail();
        }
        return AjaxResult.me().success();
    }

}
